"use strict";

const HtmlWebpackPlugin = require("html-rspack-plugin");

class DepHtmlPlugin {
  PLUGIN_NAME = "DepHtmlPlugin";

  /**
   * @param {import('@rspack/core').Compiler} compiler
   */
  apply(compiler) {
    const infoMessage = `---- ${this.PLUGIN_NAME} ----`;
    compiler.hooks.compilation.tap(this.PLUGIN_NAME, (compilation) => {
      HtmlWebpackPlugin.getCompilationHooks(compilation).afterEmit.tapAsync(
        this.PLUGIN_NAME,
        (data, cb) => {
          console.info(infoMessage, data.outputName);
          cb(null, data);
        },
      );
    });
  }
}

module.exports = DepHtmlPlugin;
